﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.Assert;
using CommunitySystem.Ctrls;
using CommunitySystem.PublicOfficialSelectionService;
using CommunitySystem.Views;
using EHR.Common;

namespace CommunitySystem
{
    public partial class ShenPiControl : AsyncCtrl, IReturnListenerc
    {
        private PublicOfficialSelectionServiceClient Client = new PublicOfficialSelectionServiceClient();
        #region IReturnListenerc 成员
        public void BeginReturn()
        {
            //Load();
        }
        #endregion
        public NavMoveSwitch Nav { get; set; }
        private ObservableCollection<PublicOfficialRecordModel> selectedempmodel =
            new ObservableCollection<PublicOfficialRecordModel>();

        private EmpbasicService.EmpBasicServiceClient Client1 = new EmpbasicService.EmpBasicServiceClient();
        public ShenPiControl()
        {
            InitializeComponent();
            for (int i = DateTime.Today.Year; i > DateTime.Today.Year - 10; i--)
            {
                ComboBoxItem cbi = new ComboBoxItem();
                cbi.Content = i.ToString();
                cbi.Tag = i;
                nian.Items.Add(cbi);
            }
            nian.SelectedIndex = 0;
            ComboBoxItem ci = new ComboBoxItem();
            ci.Content = "选调交流";
            ci.IsSelected = true;
            ComboBoxItem ci1 = new ComboBoxItem();
            this.Nav = new NavMoveSwitch();
            ci1.Content = "竞争性选拔";
            tiaojian.Items.Add(ci);
            tiaojian.Items.Add(ci1);
            Load();
        }
        public void Load()
        {
            if (Session.LoginUser.LoginName != "admin")
            {
                Client1.GetDengLuOrgCompleted += new EventHandler<EmpbasicService.GetDengLuOrgCompletedEventArgs>(Client_GetDengLuOrgCompleted);
                Client1.GetDengLuOrgAsync(Session.LoginUser.LoginName);
            }
            else
            {
                Client.GetShenPiCompleted += new EventHandler<GetShenPiCompletedEventArgs>(Client_GetShenPiCompleted);
                Client.GetShenPiAsync(DateTime.Today.Year - nian.SelectedIndex, ((System.Windows.Controls.ContentControl)
                                                                     (((ComboBoxItem)tiaojian.SelectedItem))).Content.
                                                                        ToString(), islock, "");
            }
            
        }
        public String[] Oldorgids;

        void Client_GetDengLuOrgCompleted(object sender, EmpbasicService.GetDengLuOrgCompletedEventArgs e)
        {
            if (!string.IsNullOrEmpty(e.Result))
            {
                Oldorgids = e.Result.Split(',');
            }
            string ss = "";
            foreach (string ii in Oldorgids)
                ss += ii + ",";
            ss = ss.Substring(0, ss.Length - 1);
            Client.GetShenPiCompleted += new EventHandler<GetShenPiCompletedEventArgs>(Client_GetShenPiCompleted);
            Client.GetShenPiAsync(DateTime.Today.Year - nian.SelectedIndex, ((System.Windows.Controls.ContentControl)
                                                                 (((ComboBoxItem)tiaojian.SelectedItem))).Content.
                                                                    ToString(), islock, ss);
        }

        void Client_GetShenPiCompleted(object sender, GetShenPiCompletedEventArgs e)
        {
            selectedempmodel = e.Result;
            DGRole.ItemsSource = e.Result;
        }

        private void NewData_Click(object sender, RoutedEventArgs e)
        {
            var seljw = this.DGRole.SelectedItem as PublicOfficialRecordModel;
            if (seljw != null)
            {
                ShenPiControl1 view = new ShenPiControl1(Convert.ToInt32(seljw.OrgID),seljw.OrgName);
                view.Nav = Nav;
                Nav.ShowNextPage(seljw.OrgName + "-考察情况", view, this);
            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要办理/查看的单位！");
        }

        private void ChaData_Click(object sender, RoutedEventArgs e)
        {
            Load();
        }


        private string islock = "0";
        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            islock = "1";
        }

        private void chkHiddenCols_Unchecked(object sender, RoutedEventArgs e)
        {
            islock = "0";
        }
    }
}
